from building import *

CWD = GetCurrentDir()
objs = Glob("src/*.cpp") + Glob("src/loader/*.c")
objsApp = Glob("src/custom/*.c")


@register_library
class LibraryLoader(Library):
    def config(self):
        self.include = "%s/src" % (CWD)
        self.LIBS = ["SRec", "Crc", "IsoTp"]
        self.CPPPATH = ["$INFRAS"]
        self.source = objs + objsApp


# scons --lib=LoaderFBL --prebuilt
for obj in objsApp:

    @classmethod
    def config(self):
        b = self.obj.rstr()[:-2]
        self.source = Glob(b + ".c")
        self.LIBS = ["AsOne"]
        self.CPPPATH = ["$INFRAS"]
        self.Install(self, "../one")

    libName = os.path.basename(obj.rstr())[:-2]
    libName = libName[0].upper() + libName[1:]
    cls = type(
        "LibraryLoader%s" % (libName),
        (Library,),
        {
            "name": "Loader" + libName,
            "obj": obj,
            "shared": True,
            "compiler": "QMake",
            "config": config,
            "typed_class": True,
        },
    )
    register_library(cls)

objsCmd = Glob("utils/loader_cmd.c")


@register_application
class ApplicationLoader(Application):
    def config(self):
        self.LIBS = ["AsOne"]
        self.CPPPATH = ["$INFRAS"]
        self.Append(CPPDEFINES=["USE_STD_DEBUG", "USE_STD_PRINTF"])
        self.source = objsCmd
        self.Install("../one")
